package com.ch7;

import java.sql.Connection;
import java.util.concurrent.TimeUnit;

/**
 * @author woldier
 * @version 1.0
 * @description TODO
 * @date 2023/5/16 13:57
 **/
public class Demo02 {
    public static void main(String[] args) {
        Pool pool = new Pool(3);
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                Connection connection = pool.get();
                try {

                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } finally {
                    pool.giveBack(connection);

                }
            }, "t" + (i + 1)).start();
        }

    }

}
